package com.qtjf.qtmoneyservice.view;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.WindowManager;

/**
 * Created by Administrator on 2017/7/17 0017.
 */

public class MySurfaceView extends SurfaceView{

    private SurfaceHolder mSurfaceHolder;
    Canvas mCanvas;
    Paint mPaint;
    int width=0;
    int height=0;
    float scale=0;
    public MySurfaceView(Context context) {
        super(context);
        init(context);
    }
    public MySurfaceView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    private void init(Context context) {
        WindowManager wm = ((Activity)context).getWindowManager();

        //后面转移到启动页
        width=wm.getDefaultDisplay().getWidth();
        height=wm.getDefaultDisplay().getHeight();
        scale=this.getResources().getDisplayMetrics().density;

        mSurfaceHolder=getHolder();
       /* mSurfaceHolder.addCallback(this);*/
        setFocusable(true);
        setFocusableInTouchMode(true);
        this.setKeepScreenOn(true);

        mPaint=new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setStrokeWidth(5);
        mPaint.setColor(Color.YELLOW);
        mPaint.setStyle(Paint.Style.STROKE);
    }

   /* @Override
    public void surfaceCreated(SurfaceHolder surfaceHolder) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                mCanvas=mSurfaceHolder.lockCanvas();
                mCanvas.drawRect(20*scale,(height-(width-40*scale)/3*2)/2,width-20*scale,(height+(width-40*scale)/3*2)/2,mPaint);
                mSurfaceHolder.unlockCanvasAndPost(mCanvas);
            }
        }).start();
    }

    @Override
    public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder surfaceHolder) {

    }

    @Override
    public void run() {

    }*/
}
